﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Windows.Input;

namespace valhalla
{
    public class DataIntoXML
    {

        private string _filename;
        public DataIntoXML(string fileName)
        {
            _filename = fileName;
        }


        public List<ASPNETX_WPFPolygon> GetPolygons()
        {
            FileInfo textFile;
            StreamReader sr;
            try
            {
                textFile = new FileInfo(_filename);
                sr = textFile.OpenText();
                List<ASPNETX_WPFPolygon> result = ASPNETX_Adapter.DeSerializePolygon(sr.ReadToEnd());
                sr.Dispose();
                return result;
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
            
        }

        public List<ASPNETX_WPFPolygon> GetPolygons(Func<ASPNETX_WPFPolygon, bool> filter)
        {             
            try 
	        {
                List<ASPNETX_WPFPolygon> result = new List<ASPNETX_WPFPolygon>();
                foreach (ASPNETX_WPFPolygon polygon in GetPolygons())
                {
                    if (filter(polygon))
                    {
                        result.Add(polygon);
                    }
                }
                return result;
	        }
	        catch (Exception)
	        {
        		
		        throw;
	        }                    
        }
    }

    
}
